package com.dhcc.bpm.common.redisMessage;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;


@Slf4j
@NoArgsConstructor
public class RedisListingConsumer extends Thread {
   private String name;
   private static StringRedisTemplate stringRedisTemplate;

  private static StringRedisTemplate stringRedisTemplate(){
    if (stringRedisTemplate == null){
        stringRedisTemplate = SpringUtil.getBean("stringRedisTemplate");
    }
    return stringRedisTemplate;
  }

    public RedisListingConsumer(String name) {
        this.name = name;
    }

    @Override
    public void run(){
      log.info("执行监听---start！");
        while(true) {
            if(stringRedisTemplate().opsForList().size(name) > 0){
                Object message = stringRedisTemplate().opsForList().rightPop(name, -1 , TimeUnit.MILLISECONDS);;
                log.info("消费消息结果：{}", message);
            }
//            log.info("执行监听---end！");
        }
    }

}
